.MODEL small

MPrintString macro string
	push ax
	push dx
	mov ah,09h
		mov dx,offset string
	int 21h
	pop dx
	pop ax
endm

.STACK
.DATA
	machten10 dw 100, 10, 1
	endl db 10, 13, '$'
	komma db ", $"
	oldnrticks dw 0
	oldmousestate dw 0
.CODE
.STARTUP
	xor ax, ax			; initialize mouse
		int 33h
	mov ax, 1			; show pointer
		int 33h
mainloop:
	xor ah, ah			; read system clock ticks
		int 1Ah
	mov bx, dx
	sub dx, oldnrticks	; 18,20 clock ticks per second = 0,05 s/ct
	cmp dx, 1			; 2 clock ticks ~ 0,10 seconds
	jb mainloop
	mov oldnrticks, bx
	mov ah, 1
		int 16h
	cmp al, 27
	jz einde
	xor bx, bx
	mov ax, 3			; get buttons status and position
		int 33h
	test bx, 0FFFFh
	jz checkreleased
	mov oldmousestate, bx
	jmp mainloop
checkreleased:
	test oldmousestate, 0FFFFh
	jz mainloop
	mov oldmousestate, 0	 
	push cx
	call PrintCard
	MPrintString komma
	push dx
	call PrintCard
	MPrintString endl
	jmp mainloop
einde:
	xor al, al			; flush keyboard buffer
		mov ah, 0Ch
		int 21h
.EXIT

PrintCard proc near
	push bp				; save previous base pointer
	mov bp,sp			; update base pointer
	push ax				; saving context
		push dx
		push cx
		push si
		push di
	mov bx,[bp+4]		; get cardinal to print
	test bx, 0FFFFh
	jnz nietnul
	mov ah, 02h			; behandel welnul
		mov dl, '0'
		int 21h
	jmp gedaan
nietnul:
	mov si, offset machten10
volgendcijfer:
	cmp bx, [si]
	jge huidigcijfer
	add si, 2
	jmp volgendcijfer
huidigcijfer:
	mov ax, bx
	cwd
	div word ptr [si]	; deel door macht van 10, res in ax
	mov bx, dx			; rest in bx
	mov dl, al			; resultaat in dl
	add dl, 48			; cijfer naar ascii teken, print teken
		mov ah, 2
		int 21h	
	cmp word ptr [si], 1	; laatste cijfer?	
	je gedaan
	add si, 2
	jmp huidigcijfer
gedaan:
	pop di				; restore context
		pop si
		pop cx
		pop dx
		pop ax
    pop bp				; restore bp
    ret 4				; return and freeing param from stack (4 bytes)
PrintCard endp

end